<?php
namespace app\adminbackstage\controller;
//use think\facade\Session;
use think\facade\Request;
use app\adminbackstage\model\Parameter;


/**
 * 站点参数控制
 *
 * @author asus80
 */
class ParameterController {

    //全部参数
    public function parameterList(){
        $a_uid = Request::param('a_uid');//管理员ID
        $page = Request::param('page');
        $num = Request::param('num');
        $p_name = Request::param('p_name');
        $p_explain = Request::param('p_explain');
        
        
        $where = [];
        $where[] = ['enable','=',1];
        if(!empty($p_name)){
            $where[] = ['p_name','like','%'.$p_name.'%'];
        }
        if(!empty($p_explain)){
            $where[] = ['p_explain','like','%'.$p_explain.'%'];
        }
        $parameter = new Parameter();
        

        $listinfo = $parameter->listParameter($page,$num,$where)->toArray();

        $count = $parameter->countParameter($where); 
        
        return json(['code' => 1, 'msg' => lang(''), 'data' => $listinfo, 'count' => $count]);
    }
    
    public function parameterEdit(){
        $id = Request::param('id');
//        $p_name = Request::param('p_name');
        $p_value = Request::param('p_value');
        
        $parameter = new Parameter();
        $update = ['p_value'=>$p_value];
        $parameter->updateParameter($id,$update);
        return json(['code' => 1, 'msg' => lang(''), 'data' => '', 'count' =>'']);
    }
}
